package com.ruoyi.common.utils;

import java.util.Random;

/**
 * @author LvKinfy
 * Create on 2019/4/9
 * Desc 随机数生成工具
 **/
public class RandomUtil {
  private final static Random random = new Random();

  /**
   * 获取[0,N]范围的随机数，nextInt入参必须>0
   *
   * @param bound
   * @return
   */
  public static int getRandom(int bound) {
    if (bound <= 0) {
      bound = 1;
    }
    return random.nextInt(bound);
  }

  /**
   * 获取指定范围[min,max]的随机数,nextInt入参必须>0
   *
   * @param min
   * @param max
   * @return
   */
  public static int getBetweenRandom(int min, int max) {
    if (min == max) {
      return max;
    }
    if (min > max) {
      return max + random.nextInt(min - max);
    }
    return min + random.nextInt(max - min);
  }
}
